<template>
	<view class="content">
		<view class="ipts">
			<view class="info-item" v-if="show">
				<view class="info-item-left">
					<image src="/static/phone.png" mode=""></image>
					<view class="shuxian"></view>
				</view>
				<input type="text" v-model="mobile" placeholder="请输入手机号" placeholder-class="place-class">
			</view>
			<view class="info-item" v-else>
				<view class="info-item-left">
					<image src="/static/id.png" mode=""></image>
					<view class="shuxian"></view>
				</view>
				<input type="text" v-model="car" placeholder="请输入身份证号" placeholder-class="place-class">
			</view>
			<view class="hengxian"></view>
			<view class="info-item" v-if="show">
				<view class="info-item-left">
					<image src="/static/yzm.png" mode=""></image>
					<view class="shuxian"></view>
				</view>
				<input type="text" v-model="myCode" placeholder="请输入验证码" placeholder-class="place-class">
				<view class="test-code" @click="getCode">获取验证码</view>
			</view>
			<view class="hengxian"></view>
			<view class="info-item">
				<view class="info-item-left">
					<image src="/static/suo.png" mode=""></image>
					<view class="shuxian"></view>
				</view>
				<input v-model="pswd" type="text" placeholder="请输入新密码" placeholder-class="place-class">
			</view>
			<view class="hengxian"></view>
			<view class="validation">
				<text @tap="userId" v-if="show">身份证验证</text>
				<text @tap="userPhone" v-else>手机号验证</text>
			</view>
		</view>
		<view class="btn" @click="subimit">立即修改</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile: '',
				car: '',
				myCode: '',
				pswd: '',
				type: 1,
				show: true
			};
		},
		onLoad() {

		},
		onShow() {

		},

		methods: {
			userId() {
				this.show = false
				this.mobile = ''
				this.type = 2
			},
			userPhone() {
				this.show = true
				this.car = ''
				this.type = 1
			},
			getCode() {
				let that = this
				if (that.mobile == '') {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					})
					return
				}
				if (!(/^1[3456789]\d{9}$/.test(that.mobile))) {
					uni.showToast({
						title: '手机号格式不正确',
						icon: 'none'
					})
					return
				}
				this.$u.post('/sms/send', {
					mobile: that.mobile,
					event: 'resetpwd'
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			subimit() {
				let that = this
				if (this.type == 1) {
					if (!this.mobile) return this.$showToast('请输入手机号')
					if (!this.myCode) return this.$showToast('请输入验证码')
					if (!this.pswd) return this.$showToast('请输入新密码')
				}
				if (this.type == 2) {
					if (!this.car) return this.$showToast('请输入身份证号')
					if (!this.pswd) return this.$showToast('请输入新密码')
				}
				uni.showLoading({
					title: '修改中...'
				})
				setTimeout(() => {
					this.$u.post('/common/resetpwd', {
						id_car: this.car,
						mobile: that.mobile,
						captcha: that.myCode,
						newpassword: that.pswd,
						type: this.type
					}).then(res => {
						uni.hideLoading()
						that.$showToast(res.msg)
						if (res.code == 1) {
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								})
							}, 1000)
						}
					})
				}, 800)

			}
		},

	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #F5F5F5;
		// padding-bottom: 200rpx;
		// margin-bottom: 150rpx;
	}

	.content {
		padding-bottom: 140rpx;
	}

	.validation {
		padding-top: 39rpx;
		width: 700rpx;
		margin: 0 auto;
		text-align: end;
		color: #2979ff;
	}

	.ipts {
		background-color: #fff;
		margin-top: 30rpx;
	}

	.info-item {
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 100rpx;
		width: 100%;
		padding: 0 30rpx;
		background-color: #fff;
		color: #333;

		input {
			flex: 1;
			text-align: left;
			font-size: 28rpx;
		}

		.info-item-left {
			display: flex;
			width: 10%;

			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 8rpx;
			}

			.shuxian {
				width: 2rpx;
				height: 32rpx;
				background: #dddddd;
				border-radius: 2rpx;
			}
		}
	}

	.hengxian {
		width: 700rpx;
		height: 2rpx;
		background-color: #dddddd;
		margin: 0 auto;
	}

	.place-class {
		font-size: 28rpx;
		color: #999;
	}

	.btn {
		width: 646rpx;
		height: 80rpx;
		margin: 74rpx auto;
		text-align: center;
		line-height: 80rpx;
		border-radius: 10rpx;
		background-image: linear-gradient(to bottom, #2979ff, #2979ff);
		font-size: 32rpx;
		color: #E5EFFE;
	}

	.btn:active {
		background: rgba(0, 0, 0, 0.4);
	}

	.test-code {
		padding: 10rpx 10rpx;
		font-size: 24rpx;
		color: #003690;
		border: 2rpx solid #003690;
		border-radius: 8rpx;
	}

	.test-code:active {
		background: rgba(69, 82, 202, 0.4);
		color: #fff;
	}
</style>
